package com.inspur.xiaoju.controller;

import com.inspur.xiaoju.common.ApiResponse;
import com.inspur.xiaoju.dto.CreateSurveyResponseDto;
import com.inspur.xiaoju.model.SurveyResponse;
import com.inspur.xiaoju.service.SurveyResponseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.HashMap;  // 添加这个导入
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/survey-responses")
public class SurveyResponseController {

    @Autowired
    private SurveyResponseService surveyResponseService;
    
    @PostMapping
    public ApiResponse<Map<String, String>> create(@Valid @RequestBody CreateSurveyResponseDto createDto) {
        SurveyResponse response = surveyResponseService.create(createDto);
        // 替换 Map.of() 为 HashMap
        Map<String, String> result = new HashMap<>();
        result.put("id", response.getId());
        return ApiResponse.success(result);
    }
    
    @GetMapping("/{id}")
    public ApiResponse<SurveyResponse> findById(@PathVariable String id) {
        return ApiResponse.success(surveyResponseService.findById(id));
    }
    
    @GetMapping("/survey/{surveyId}")
    public ApiResponse<List<SurveyResponse>> findBySurveyId(@PathVariable String surveyId) {
        return ApiResponse.success(surveyResponseService.findBySurveyId(surveyId));
    }
    
    @GetMapping("/path/{surveyPath}")
    public ApiResponse<List<SurveyResponse>> findBySurveyPath(@PathVariable String surveyPath) {
        return ApiResponse.success(surveyResponseService.findBySurveyPath(surveyPath));
    }
}